home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / jpsrc2.zip / JDSAMPLE.C < prev    next >
C/C++ Source or Header  |  1991-10-03  |  4KB  |  134 lines

  1. /*
  2.  * jdsample.c
  3.  *
  4.  * Copyright (C) 1991, Thomas G. Lane.
  5.  * This file is part of the Independent JPEG Group's software.
  6.  * For conditions of distribution and use, see the accompanying README file.
  7.  *
  8.  * This file contains un-subsampling routines.
  9.  * These routines are invoked via the unsubsample and
  10.  * unsubsample_init/term methods.
  11.  */
  12.  
  13. #include "jinclude.h"
  14.  
  15.  
  16. /*
  17.  * Initialize for un-subsampling a scan.
  18.  */
  19.  
  20. METHODDEF void
  21. unsubsample_init (decompress_info_ptr cinfo)
  22. {
  23.   /* no work for now */
  24. }
  25.  
  26.  
  27. /*
  28.  * Un-subsample pixel values of a single component.
  29.  * This version only handles integral sampling ratios.
  30.  */
  31.  
  32. METHODDEF void
  33. unsubsample (decompress_info_ptr cinfo, int which_component,
  34.          long input_cols, int input_rows,
  35.          long output_cols, int output_rows,
  36.          JSAMPARRAY above, JSAMPARRAY input_data, JSAMPARRAY below,
  37.          JSAMPARRAY output_data)
  38. {
  39.   jpeg_component_info * compptr = cinfo->cur_comp_info[which_component];
  40.   short h_expand, v_expand, h, v;
  41.   int inrow, outrow;
  42.   long incol;
  43.   JSAMPROW inptr, outptr;
  44.   JSAMPLE invalue;
  45.  
  46.   /* TEMP FOR DEBUGGING PIPELINE CONTROLLER */
  47.   if (input_rows != compptr->v_samp_factor ||
  48.       output_rows != cinfo->max_v_samp_factor ||
  49.       (input_cols % compptr->h_samp_factor) != 0 ||
  50.       (output_cols % cinfo->max_h_samp_factor) != 0 ||
  51.       output_cols*compptr->h_samp_factor != input_cols*cinfo->max_h_samp_factor)
  52.     ERREXIT(cinfo->emethods, "Bogus unsubsample parameters");
  53.  
  54.   h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  55.   v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  56.  
  57.   outrow = 0;
  58.   for (inrow = 0; inrow < input_rows; inrow++) {
  59.     for (v = 0; v < v_expand; v++) {
  60.       inptr = input_data[inrow];
  61.       outptr = output_data[outrow++];
  62.       for (incol = 0; incol < input_cols; incol++) {
  63.     invalue = GETJSAMPLE(*inptr++);
  64.     for (h = 0; h < h_expand; h++) {
  65.       *outptr++ = invalue;
  66.     }
  67.       }
  68.     }
  69.   }
  70. }
  71.  
  72.  
  73. /*
  74.  * Un-subsample pixel values of a single component.
  75.  * This version handles the special case of a full-size component.
  76.  */
  77.  
  78. METHODDEF void
  79. fullsize_unsubsample (decompress_info_ptr cinfo, int which_component,
  80.               long input_cols, int input_rows,
  81.               long output_cols, int output_rows,
  82.               JSAMPARRAY above, JSAMPARRAY input_data, JSAMPARRAY below,
  83.               JSAMPARRAY output_data)
  84. {
  85.   if (input_cols != output_cols || input_rows != output_rows) /* DEBUG */
  86.     ERREXIT(cinfo->emethods, "Pipeline controller messed up");
  87.  
  88.   jcopy_sample_rows(input_data, 0, output_data, 0, output_rows, output_cols);
  89. }
  90.  
  91.  
  92.  
  93. /*
  94.  * Clean up after a scan.
  95.  */
  96.  
  97. METHODDEF void
  98. unsubsample_term (decompress_info_ptr cinfo)
  99. {
  100.   /* no work for now */
  101. }
  102.  
  103.  
  104.  
  105. /*
  106.  * The method selection routine for unsubsampling.
  107.  * Note that we must select a routine for each component.
  108.  */
  109.  
  110. GLOBAL void
  111. jselunsubsample (decompress_info_ptr cinfo)
  112. {
  113.   short ci;
  114.   jpeg_component_info * compptr;
  115.  
  116.   if (cinfo->CCIR601_sampling)
  117.     ERREXIT(cinfo->emethods, "CCIR601 subsampling not implemented yet");
  118.  
  119.   for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  120.     compptr = cinfo->cur_comp_info[ci];
  121.     if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  122.     compptr->v_samp_factor == cinfo->max_v_samp_factor)
  123.       cinfo->methods->unsubsample[ci] = fullsize_unsubsample;
  124.     else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  125.          (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0)
  126.       cinfo->methods->unsubsample[ci] = unsubsample;
  127.     else
  128.       ERREXIT(cinfo->emethods, "Fractional subsampling not implemented yet");
  129.   }
  130.  
  131.   cinfo->methods->unsubsample_init = unsubsample_init;
  132.   cinfo->methods->unsubsample_term = unsubsample_term;
  133. }
  134.